#pragma once
#include "Includes.h"

#define JUNK_CODE \
	__asm mov eax, eax \
	__asm mov edi, edi \
	__asm mov edi, edi \
	__asm NOP \
	__asm mov eax, eax \
	__asm NOP \
	__asm NOP \
	__asm NOP \
	__asm NOP \
	__asm mov ecx, ecx \
	__asm mov ecx, ecx \
	__asm NOP \
	__asm NOP \
	__asm NOP \
	__asm mov edi, edi \
	__asm NOP \
	__asm NOP \
	__asm NOP \
	__asm mov ecx, ecx \
	__asm NOP \
	__asm mov eax, eax \
	__asm NOP \
	__asm mov eax, eax \
	__asm NOP \
	__asm NOP \
	__asm NOP \
	__asm NOP \
	__asm NOP 

class XorStr
{
public:
        XorStr(int length, int key, ...)
        {
                data.reserve(length);

				JUNK_CODE;
                int xor = key;
                int index = 0;
 
                va_list vl;
				va_start(vl, key);
				JUNK_CODE;
                for (int i = 0; i <= length / 4; ++i)
                {
                        int hash = va_arg(vl, int);
 
                        for (int j = 0; j < 4; j++)
                        {
                                if (index >= length)
                                {
                                        break;
                                }
 
                                WORD word = HIWORD(hash);
                                if (j >= 2)
                                {
                                        word = LOWORD(hash);
                                }
								JUNK_CODE;
 
                                switch (j)
                                {
                                case 0:
								case 2:
									JUNK_CODE;
                                        data += HIBYTE(word) ^ xor;
                                        break;
                                case 1:
                                case 3:
                                        data += LOBYTE(word) ^ xor;
                                        break;
                                }
								xor += 127;
								JUNK_CODE;
                                xor %= 256;
 
                                ++index;
                        }  
                }
                va_end(vl);
        }
 
        operator const std::string&() const
        {
                return data;
        }
 
        const char* c_str() const
        {
                return data.c_str();
        }
 
private:
        std::string data;
};